import { QFrame_App } from "../../ttapi_layer2/ttlayer2.js";
import { UserData, UserState } from "../game.js";
import * as tt2 from "../../ttapi_layer2/ttlayer2.js"
import { tt } from "../../ttapi_interface/ttapi.js";
import { State_MainMenu } from "./state_mainmenu.js";

export class State_CardInfo extends UserState {
    override OnInit(statemgr: QFrame_App<UserData>): void {
        super.OnInit(statemgr);
        this.InitAsync();
    }
    override  OnExit(): void {
        let _ui = this.userdata.scene.GetUI();
        _ui.removeChildAll();
    }
    private _inited: boolean = false;
    async InitAsync(): Promise<void> {
        let _ui = this.userdata.scene.GetUI();
        let _uiMidY = _ui.getWorldRect().Height / 2 - 20;

      
        {
            let l = new tt2.QUI_Label(this.app.font, "卡片信息");
            l.localRect.setVPosByTopBorder(20, _uiMidY - 120);
            _ui.addChild(l);
        }
        {
            let l = new tt2.QUI_Label(this.app.font, "这个模式还没开发完");
            l.localRect.setVPosByTopBorder(20, _uiMidY - 100);
            _ui.addChild(l);
        }
        {
            let _foot = await tt2.QFrame_ResMgr.LoadStandaloneSpriteAsync("footer.png");
            let _imgfoot = new tt2.QUI_Image(_foot);
            _imgfoot.localRect.setHPosByCenter(240);
            _imgfoot.localRect.setVPosByBottomBorder(_foot.totalHeight, 0);
            _ui.addChild(_imgfoot);
        }

        {
            let _btn1 = await this.CreateBtn("退出");
            _btn1.localRect.setVPosByTopBorder(40, _uiMidY - 0);
            _ui.addChild(_btn1);
            _btn1.OnClick = () => {
                this.app.ChangeState(new State_MainMenu());
            }
        }


        this._inited = true;
    }
    async CreateBtn(text: string): Promise<tt2.QUI_Button> {
        let _btnborder = await tt2.QFrame_ResMgr.LoadStandaloneSpriteAsync("btnborder.png");
        let btn = new tt2.QUI_Button();
        btn.localRect.setHPosByCenter(160);
        btn.localRect.setVPosByBottomBorder(40, 30);
        let bimg: tt2.QUI_ImageScale9;
        {
            let s9 = new tt2.QUI_Scale9(_btnborder, new tt.Border(4, 4, 4, 4));
            let label = new tt2.QUI_Label(this.app.font, text);
            label.fontScale.X = 2;
            label.fontScale.Y = 2;
            label.color = new tt.Color(0.3, 0.3, 0.3, 1);
            bimg = new tt2.QUI_ImageScale9(s9);
            label.localRect.setAsFill();
            bimg.addChild(label);
            bimg.localRect.setAsFill();
        }
        let bimg2 = bimg.Clone() as tt2.QUI_ImageScale9;
        bimg2.color = new tt.Color(0.5, 0.5, 0.5, 1.0);

        //bimg2.localRect.setAsFill();
        btn.ElemNormal = bimg;
        btn.ElemPress = bimg2;
        return btn;
    }
}